﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security;
using System.Security.Cryptography;
using DBBase;
namespace Business
{
    public partial class dengluxinxi : Form
    {
        public static string name;
        public DateTime dstart;
        public dengluxinxi(string sname,string sip)
        {
            InitializeComponent();
            lab_dqip.Text = sip;
            name = sname;
            getjilu();
            lab_dlsj.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            getyhjilu();
             dstart = DateTime.Now;
           // timer1.Enabled = true;

            
        }
        public void getjilu()
        {
            int icount = 0;
            string syuanmima = "";
             Query mquery = new Query();
                string sql;
                sql = string.Format(@"Select * from dengluriji   Where username='{0}' and dlsj>='{1}' order by dlsj desc ", name, lab_dlsjsc.Text);
                DataTable dt = mquery.GetTable(sql);
                if (dt.Rows.Count > 0)
                {
                    if(dt.Rows.Count>1)
                    {
                        for(int i=1;i<dt.Rows.Count;i++)
                        {
                            if (!dt.Rows[i]["dlsfcg"].ToString().Trim().Contains("成功") && (!dt.Rows[i]["dlsfcg"].ToString().Trim().Contains("用户退出系统")))
                            {
                              
                                syuanmima = syuanmima + string.Format(@"{0}   {1}   {2}", dt.Rows[i]["dlsj"].ToString().Trim(), dt.Rows[i]["dengluIP"].ToString().Trim(), dt.Rows[i]["dlsfcg"].ToString().Trim()) + "\r\n";
                            }
                            if (dt.Rows[i]["dlsfcg"].ToString().Trim().Contains("成功"))
                            {
                                icount++;
                                lab_scip.Text = dt.Rows[i]["dengluIP"].ToString().Trim();
                                lab_dlsjsc.Text = dt.Rows[i]["dlsj"].ToString().Trim();
                                //if(icount>2)
                                {
                                   break; 
                                }
                            }
                        }
                    }
                }

                text_jilu.Text = syuanmima;
        }


        public void getyhjilu()
        {
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from USERE   Where YHLB='{0}' ", name);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                   
                    //lab_dlsjsc.Text = dt.Rows[i]["ZJDLSJ"].ToString().Trim();
                    lab_mmxcxgsj.Text = dt.Rows[i]["MMYXQ"].ToString().Trim();
                    lab_yhdlyxq.Text = string.Format(@"{0} ~ {1}", dt.Rows[i]["YHSDSJ"].ToString().Trim(), Convert.ToDateTime(dt.Rows[i]["YHYXQ"].ToString().Trim()));
                }
            }

           
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (DateDiff(DateTime.Now, dstart) > 3000)
            {
                this.Close();
 
            }
        }

   
        private double DateDiff(DateTime DateTime1, DateTime DateTime2)
        {
            double dateDiff = 0;
            TimeSpan ts = DateTime1.Subtract(DateTime2).Duration();
            dateDiff = ts.Days * 60 * 60 * 60 * 1000 + ts.Hours * 60 * 60 * 1000 + ts.Minutes * 60 * 1000 + ts.Seconds * 1000 + ts.Milliseconds;
            return dateDiff;
        }
       
    }
}
